<?php

###########################################################################
#   Copyright (C) 2012 CDNPAL LTD by Christopher Gu                       #
#   resources@cdnpal.com                                                  #
#                                                                         #
#   coded for Php 4.3/5.X and above                                       #
#   and AllowOverride all for .htaccess                                   #
#                                                                         #
#   This program is free software released                                #
#   under the GPL version 2 license:                                      #
#   http://www.gnu.org/licenses/gpl-2.0.htm                               #
#                                                                         #
#   This program is distributed WITHOUT ANY WARRANTY                      #
#   or FITNESS FOR A PARTICULAR PURPOSE.                                  #
#                                                                         #
#   DADF-SDK                                                              #
#                                                                         #
###########################################################################

class AcceptResponseService 
{
	
	public static function process_dadf_accept($accept_reponse_list) {
		$accept_response_id_list = array();
		
		foreach ($accept_reponse_list as $accept_reponse):

			$accepted_response_id_list[] = self::createAcceptResponse($accept_reponse);
		
		endforeach;
		
		$transformer = new OutgoingAcceptedTransformer($accepted_response_id_list, 0, 'Outgoing');
		header("Content-type: text/xml");
		echo $transformer->xmlData;
	}
	
	public static function createAcceptResponse($accept_response) {
		
		$reason = "";
		
		$offer_accept_workflow 					= new OfferAcceptWorkflow();
		$accept_response_accepted 				= $offer_accept_workflow->decide_valid_offer_accept_response($accept_response, $reason);
		
		$accepted_response = new OutgoingAcceptedResponse();
		
		$accepted_response->AcceptID			= $accept_response->AcceptID;
		$accepted_response->ID					= $accept_response->ID;
		$accepted_response->Accepted			= $accept_response_accepted == true ? 1 : 0;
		$accepted_response->Reason				= $reason;
		$accepted_response->save();
		
		return $accepted_response->OutgoingAcceptedResponseID;
		
	}
	

}